//
//  ZXZHomeGoodsViewController.m
//  sheyingzu
//
//  Created by tyu on 29.5.24.
//

#import "ZXZHomeGoodsViewController.h"



#import "ZXZGowuView.h"
#import "ZXZOrderViewController.h"


@interface ZXZHomeGoodsViewController ()

@property(nonatomic,weak) UIScrollView *ScrollView;

@property(nonatomic,weak) ZXZGowuView *goodsView1;

@property(nonatomic,weak) UIImageView  *topImageV;

@property(nonatomic,weak) UIImageView  *bottImageV;


@property(nonatomic,copy) NSString *goodsTitle;
@property(nonatomic,copy) NSString *goodsImg;


@end

@implementation ZXZHomeGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];

}

- (void)bac_addUI
{
    [super bac_addUI];
    [self setupView];
//    self.bacTitleLabel.text = @"详情";
    [self.view bringSubviewToFront:self.navView];
    [self setupNav];
    [self setBottomView];
    
    [self updata];
}

- (void)updata
{
    
    
    if (self.index == 1) {
        self.goodsTitle =  @"Insta360 x4";
        self.goodsImg =  @"goods1";

        self.goodsView1.TitleLab.text =self.goodsTitle;
        self.goodsView1.ImgV.image = [UIImage imageNamed:self.goodsImg];
        self.topImageV.image = [UIImage imageNamed:@"Insta360x4"];
        self.topImageV.frame = CGRectMake(10, CGRectGetMaxY(self.goodsView1.frame)+10, ScreenWidth-20, (ScreenWidth-20)/0.3729);


    }else if (self.index == 2){
        self.goodsTitle =  @"GoPro";
        self.goodsImg =  @"GoPro_02";

        self.goodsView1.TitleLab.text =self.goodsTitle;
        self.goodsView1.ImgV.image = [UIImage imageNamed:self.goodsImg];
        
        
        self.topImageV.image = [UIImage imageNamed:@"GoPro"];
        self.topImageV.frame = CGRectMake(10, CGRectGetMaxY(self.goodsView1.frame)+10, ScreenWidth-20, (ScreenWidth-20)/0.474);


    }else if (self.index == 3){
        self.goodsTitle =  @"DJI";
        self.goodsImg =  @"DJI_03";

        self.goodsView1.TitleLab.text =self.goodsTitle;
        self.goodsView1.ImgV.image = [UIImage imageNamed:self.goodsImg];
        
        
        self.topImageV.image = [UIImage imageNamed:@"DJI"];
        self.topImageV.frame = CGRectMake(10, CGRectGetMaxY(self.goodsView1.frame)+10, ScreenWidth-20, (ScreenWidth-20)/0.438);

    }

    self.bottImageV.frame = CGRectMake(10, CGRectGetMaxY(self.topImageV.frame)+10, ScreenWidth-20, (ScreenWidth-20)/1.665);
    self.ScrollView.contentSize = CGSizeMake(ScreenWidth, CGRectGetMaxY(self.bottImageV.frame)+100);

    

}

- (void)setupNav
{
    UILabel *navLeftLab = [UIView lableWithText:@"我要租" andColor:[UIColor blackColor] andFont:20];
    [self.navView addSubview:navLeftLab];
    navLeftLab.frame = CGRectMake(CGRectGetMaxX(self.bacbBackBtn.frame)+15, 50, 100, 40);
    
    
    
    UIButton *addGowuBtn = [[UIButton alloc] init];
    [self.navView addSubview:addGowuBtn];
    [addGowuBtn setTitle:@"加入购物车" forState:UIControlStateNormal];
    [addGowuBtn setTitleColor:[UIView ColorWithHexString:@"#333333"] forState:UIControlStateNormal];

    addGowuBtn.frame = CGRectMake(ScreenWidth-120, 50, 100, 40);
    [addGowuBtn addTarget:self action:@selector(addGowuBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)addGowuBtnClick
{
    [userDef setValue:[NSString stringWithFormat:@"%d",self.index] forKey:@"gouwutype"];
    [userDef setValue:[NSString stringWithFormat:@"%@",self.goodsTitle] forKey:@"gouwuTile"];
    [userDef setValue:[NSString stringWithFormat:@"%@",self.goodsImg] forKey:@"gouwuImage"];
    
    [NotifyLabel NotifyWithString:@"已加入购物车!"];
    
}


- (void)setupView{
    
    UIScrollView *ScrollV = [[UIScrollView alloc]init];
    [self.view addSubview:ScrollV];
    self.ScrollView =ScrollV;

    ScrollV.contentSize = CGSizeMake(ScreenWidth, ScreenHeight*1.5);
    ScrollV.contentInset = UIEdgeInsetsMake(0, 0, -10, 0);
    ScrollV.showsVerticalScrollIndicator = NO;
    ScrollV.frame = CGRectMake(0, 100, ScreenWidth, ScreenHeight-twoShowDiff-60-100);

    ZXZGowuView *goods = [[ZXZGowuView alloc]init];
    [self.ScrollView addSubview:goods];
    self.goodsView1 = goods;

    goods.ImgV.image = [UIImage imageNamed:@"goods1"];
    goods.TitleLab.text = @"Insta360 x4";
    goods.SubLab.text = @"押金 ￥800     租金 ";
    goods.zujinLab.text = @"￥150/天";
    goods.ImgV.layer.cornerRadius = 15;
    goods.ImgV.layer.masksToBounds = YES;

    goods.ClcikBlock = ^(NSString * _Nonnull Str) {

    };
        
    CGFloat height = 140;
    CGFloat width = (ScreenWidth-30);

    self.goodsView1.frame = CGRectMake(10, 10, width, height);

    
    
    
    UIImageView *topViewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"goods_bottom_image"]];
    [self.ScrollView addSubview:topViewImage];
    self.topImageV = topViewImage;
    topViewImage.frame = CGRectMake(10, CGRectGetMaxY(self.goodsView1.frame)+10, ScreenWidth-20, (ScreenWidth-20)/1.665);

    
    
    
    UIImageView *bottImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"goods_bottom_image"]];
    [self.ScrollView addSubview:bottImage];
    self.bottImageV = bottImage;
    bottImage.frame = CGRectMake(10, CGRectGetMaxY(self.topImageV.frame)+10, ScreenWidth-20, (ScreenWidth-20)/1.665);

    
    
}


- (void)setBottomView
{
  
    UIButton *hireBtn = [[UIButton alloc] init];
    [self.view addSubview:hireBtn];
    hireBtn.frame = CGRectMake(20, ScreenHeight-twoShowDiff-50, ScreenWidth-40, 40);

    [hireBtn setTitle:@"立即下单" forState:UIControlStateNormal];
    hireBtn.backgroundColor = [UIView ColorWithHexString:@"#07C6D2"];
    [hireBtn addTarget:self action:@selector(hireBtnClick) forControlEvents:UIControlEventTouchUpInside];
    hireBtn.layer.cornerRadius = 40/2;
    hireBtn.layer.masksToBounds = YES;
    
}

- (void)hireBtnClick
{
    ZXZOrderViewController *vc = [ZXZOrderViewController new];
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)pushIndex:(int)index
{
//    ZXZHomeGoodsViewController *vc = [ZXZHomeGoodsViewController new];
//    vc.index = index;
//    [self.navigationController pushViewController:vc animated:YES];
}




@end
